package com.arcgis.app.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.transition.Fade;

public class NavigationUtil {
    public static void push(Context context, Class destActivity) {

        if (context == null) return;

        Intent intent = new Intent(context, destActivity);

//        context.startActivity(intent);
        context.startActivity(intent);
        Fade fade = new Fade();
        fade.setDuration(500);
        ((Activity) context).getWindow().setExitTransition(fade);

    }

    public static void push(Context context, Class destActivity, Bundle bundle) {

        if (context == null) return;

        Intent intent = new Intent(context, destActivity);

        intent.putExtras(bundle);

        context.startActivity(intent);

    }

    public static void pushWithResult(Activity context, Class destActivity, Bundle bundle, int resultCode) {

        if (context == null) return;

        Intent intent = new Intent(context, destActivity);

        intent.putExtras(bundle);

        context.startActivityForResult(intent, resultCode);

    }

    public static void pop(Activity context) {

        if (context == null) return;

        context.finish();

    }

    public static void popWithResult(Activity context, int code, Intent intent) {

        if (context == null) return;

        if (intent != null) {

            context.setResult(code, intent);
        } else {
            context.setResult(code);
        }

        context.finish();

    }

    public static void popToRoot(Activity context,Class desc) {

        Intent intent = new Intent(context,desc);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        context.startActivity(intent);
    }
}
